#include "ObjectsService.h"

#include "../common/YXLog.h"
#include "../common/YXMySQL.h"
#include "../common/YXResult.h"
#include "../mapper/ObjectsMapper.h"

YXResult* postObject(char* name, char* type, char* parentPath, long long size, long long lastModifiedTime) {
    char* err;
    MYSQLResult *result = insertObject(name, type, parentPath, size, lastModifiedTime);
    return NULL;
}

YXResult *getObjects(int lastId, char *parentPath) {
    const char *err;

    MYSQLResult *result = selectObjects(lastId, parentPath);
    if (result->type == MYSQL_RESULT_ERROR) {
        err = yxMYSQLResultGetErrMsg(result);
        yxMYSQLResultFree(result);
        return YXResultUtils.error(err);
    }
    yxObject *res = yxMYSQLResultGetArrayValue(result);
    if (cJSON_IsObject(res)) {
        yxArray *temp = cJSON_CreateArray();
        cJSON_AddItemToArray(temp, res);
        res = temp;
    }
    yxMYSQLResultFreeNotValue(result);

    return YXResultUtils.success(res);
}
